
#include "graphics/light.h"

namespace dw
{
namespace graphics
{

Light::Light(const LightType& lightType, 
	const Point4f& position, 
	const Vector4f& direction, 
	const Colorf& diffuse) : 
	_lightType(lightType),
	_position(position), 
	_direction(direction),
	_ambient(0, 0, 0, 1),
	_diffuse(diffuse),
	_specular(1, 1, 1, 1),
	_range(std::sqrt(std::numeric_limits< float >::max()))
{
}

Object::Type Light::getType() const
{
	return Object::LIGHT;
}

void Light::render() const
{
}

std::ostream& operator<<(std::ostream& os, const Light& light)
{
	os << dynamic_cast< const Object& >(light);
	
	os.write(reinterpret_cast< const char* >(&light._lightType), sizeof (Light::LightType));
	os.write(reinterpret_cast< const char* >(&light._position), sizeof (Point3f));
	os.write(reinterpret_cast< const char* >(&light._direction), sizeof (Vector3f));
	os.write(reinterpret_cast< const char* >(&light._ambient), sizeof (Colorf));
	os.write(reinterpret_cast< const char* >(&light._diffuse), sizeof (Colorf));
	os.write(reinterpret_cast< const char* >(&light._specular), sizeof (Colorf));
	os.write(reinterpret_cast< const char* >(&light._castShadows), sizeof (bool));
	
	return os;
}

std::istream& operator>>(std::istream& is, Light& light)
{
	is >> dynamic_cast< Object& >(light);
	
	is.read(reinterpret_cast< char* >(&light._lightType), sizeof (Light::LightType));
	is.read(reinterpret_cast< char* >(&light._position), sizeof (Point3f));
	is.read(reinterpret_cast< char* >(&light._direction), sizeof (Vector3f));
	is.read(reinterpret_cast< char* >(&light._ambient), sizeof (Colorf));
	is.read(reinterpret_cast< char* >(&light._diffuse), sizeof (Colorf));
	is.read(reinterpret_cast< char* >(&light._specular), sizeof (Colorf));
	is.read(reinterpret_cast< char* >(&light._castShadows), sizeof (bool));
	
	return is;
}

} // namespace graphics
} // namespace dw
